import random

def getRandomStr(leng, prePath, ext):
	printFileName = ''
	for i in range(leng): printFileName += random.choice('abcdefghijklmnopqrstuvABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
	return prePath + printFileName + ext

def toUTF8(obj):
	if type(obj) == type('h'):
		return unicode(obj,'utf-8')
	elif type(obj) == type(True):
		return int(obj)
	else:
		return obj


def specialToSafe(cString):
	cString = cString.replace(",", '|com|')
	cString = cString.replace("'", '|===|')
	cString = cString.replace("&", "|amps|") 
	cString = cString.replace("#", "|pnd|") 
	cString = cString.replace("@", "|at|") 
	cString = cString.replace("^", "|hat|") 
	cString = cString.replace("%", "|pcnt|") 
	cString = cString.replace("(", "|lbr|") 
	cString = cString.replace(")", "|rbr|") 
	cString = cString.replace("*", "|star|") 
	cString = cString.replace("[", "|lbra|") 
	cString = cString.replace("]", "|rbra|") 
	cString = cString.replace("?", "|qst|") 
	cString = cString.replace(":", "|col|") 
	cString = cString.replace(";", "|scol|") 
	cString = cString.replace("{", "|lcbr|") 
	cString = cString.replace("}", "|rcbr|") 
	cString = cString.replace("\"", "|dqu|") 
	#cString = cString.replace("/", "|slash|") 
	return cString


def SafeStringToSpecial(cString):
	cString = cString.replace('|===|',"'")
	cString = cString.replace("|amps|",   "&") 
	cString = cString.replace("|pnd|",    "#") 
	cString = cString.replace("|at|",     "@") 
	cString = cString.replace("|hat|",    "^") 
	cString = cString.replace("|pcnt|",   "%") 
	cString = cString.replace("|lbr|",   "(") 
	cString = cString.replace("|rbr|",   ")") 
	cString = cString.replace("|star|",   "*") 
	cString = cString.replace("|lbra|",   "[") 
	cString = cString.replace("|rbra|",   "]") 
	cString = cString.replace("|qst|",   "?") 
	cString = cString.replace("|col|",   ":") 
	cString = cString.replace("|scol|",   ";") 
	cString = cString.replace('|com|', ",")
	cString = cString.replace('|lcbr|', "{")
	cString = cString.replace('|rcbr|', "}")
	cString = cString.replace('|dqu|', "\"")
	cString = cString.replace('|nl|', "\n")

	return cString
	

